package com.lehecai.core.api.event;

import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.event.EventInfoStatus;
import com.lehecai.core.event.EventTemplateType;
import com.lehecai.core.lottery.LotteryType;
import com.lehecai.core.util.CoreDateUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * 加奖活动模板
 * Created by JSH on 2015/3/12.
 */
public class ExtraPrizeEventTemplate extends AbstractApiResultBean {

    public static final String QUERY_ID = "id";
    public static final String QUERY_EVENT_ID = "event_id";
    public static final String QUERY_STATUS = "status";
    public static final String QUERY_TYPE = "type";
    public static final String QUERY_EVENT_NAME = "event_name";
    public static final String QUERY_EVENT_TIME_START = "event_time_start";
    public static final String QUERY_EVENT_TIME_END = "event_time_end";
    public static final String QUERY_EVENT_CREATE_TIME = "event_time_end";

    public static final String SET_EVENT_ID = "event_id";
    public static final String SET_STATUS = "status";
    public static final String SET_TYPE = "type";
    public static final String SET_CONFIG = "config";

    private String eventId;                              //活动id
    private EventTemplateType eventTemplateType;         //模板类型
    private EventInfoStatus status;                      //活动状态
    private String eventName;                            //活动名称
    private Date eventTimeStart;                         //活动开始时间
    private Date eventTimeEnd;                           //活动结束时间
    private String config;                               // 加奖配置 String|json
    private List<ExtraPrizeConfig> extraPrizeConfigList; // 加奖配置列表
    private String presetHits;                           //预估参与人数

    //解析config字段信息
    private String[] lotteryType;
    private String[] playType;
    private String type;
    private String details;
    private String min;
    private String max;
    private String appGift;                     //app_gift
    private String webGift;                    //web_gift
    private String rule;
    private String appUnitPrize;               //app_unit_prize
    private String appUnitGift;                //app_unit_gift
    private String webUnitPrize;               //web_unit_prize
    private String webUnitGift;                //web_unit_gift
    private String maxGift;                    //max_gift
    private String prize_key;                  //max_gift


    public static ExtraPrizeEventTemplate convertFromJSONObject(JSONObject object) {
        if (object == null) {
            return null;
        }
        ExtraPrizeEventTemplate extraPrizeEventTemplate = new ExtraPrizeEventTemplate();
        extraPrizeEventTemplate.eventId = getString(object, "event_id");
        extraPrizeEventTemplate.eventTemplateType = EventTemplateType.getItem(getInt(object, "type"));
        extraPrizeEventTemplate.status = EventInfoStatus.getItem(getInt(object, "status"));
        extraPrizeEventTemplate.eventTimeStart = CoreDateUtils.parseDate(("".equals(getString(object, "event_time_start")) || "0000-00-00 00:00:00".equals(getString(object, "event_time_start"))) ? null : getString(object, "event_time_start"), CoreDateUtils.DATETIME);
        extraPrizeEventTemplate.eventTimeEnd = CoreDateUtils.parseDate(("".equals(getString(object, "event_time_end")) || "0000-00-00 00:00:00".equals(getString(object, "event_time_end"))) ? null : getString(object, "event_time_end"), CoreDateUtils.DATETIME);
        extraPrizeEventTemplate.config = getString(object, "config");
        extraPrizeEventTemplate.presetHits = getString(object, "preset_hits");
        extraPrizeEventTemplate.eventName = getString(object, "event_name");

        return extraPrizeEventTemplate;
    }

    public static List<ExtraPrizeEventTemplate> convertFromJSONArray(JSONArray array) {
        if (array == null) {
            return null;
        }
        List<ExtraPrizeEventTemplate> list = new ArrayList<ExtraPrizeEventTemplate>();
        for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
            JSONObject object = (JSONObject) iterator.next();
            list.add(convertFromJSONObject(object));
        }
        return list;
    }

    public String getEventId() {
        return eventId;
    }

    public void setEventId(String eventId) {
        this.eventId = eventId;
    }

    public EventTemplateType getEventTemplateType() {
        return eventTemplateType;
    }

    public void setEventTemplateType(EventTemplateType eventTemplateType) {
        this.eventTemplateType = eventTemplateType;
    }

    public EventInfoStatus getStatus() {
        return status;
    }

    public void setStatus(EventInfoStatus status) {
        this.status = status;
    }

    public String getConfig() {
        return config;
    }

    public void setConfig(String config) {
        this.config = config;
    }

    public List<ExtraPrizeConfig> getExtraPrizeConfigList() {
        return extraPrizeConfigList;
    }

    public void setExtraPrizeConfigList(List<ExtraPrizeConfig> extraPrizeConfigList) {
        this.extraPrizeConfigList = extraPrizeConfigList;
    }

    public String getEventName() {
        return eventName;
    }

    public void setEventName(String eventName) {
        this.eventName = eventName;
    }

    public Date getEventTimeStart() {
        return eventTimeStart;
    }

    public void setEventTimeStart(Date eventTimeStart) {
        this.eventTimeStart = eventTimeStart;
    }

    public Date getEventTimeEnd() {
        return eventTimeEnd;
    }

    public void setEventTimeEnd(Date eventTimeEnd) {
        this.eventTimeEnd = eventTimeEnd;
    }

    public String[] getLotteryType() {
        return lotteryType;
    }

    public void setLotteryType(String[] lotteryType) {
        this.lotteryType = lotteryType;
    }

    public String[] getPlayType() {
        return playType;
    }

    public void setPlayType(String[] playType) {
        this.playType = playType;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getDetails() {
        return details;
    }

    public void setDetails(String details) {
        this.details = details;
    }

    public String getMin() {
        return min;
    }

    public void setMin(String min) {
        this.min = min;
    }

    public String getMax() {
        return max;
    }

    public void setMax(String max) {
        this.max = max;
    }

    public String getAppGift() {
        return appGift;
    }

    public void setAppGift(String appGift) {
        this.appGift = appGift;
    }

    public String getWebGift() {
        return webGift;
    }

    public void setWebGift(String webGift) {
        this.webGift = webGift;
    }

    public String getRule() {
        return rule;
    }

    public void setRule(String rule) {
        this.rule = rule;
    }

    public String getAppUnitPrize() {
        return appUnitPrize;
    }

    public void setAppUnitPrize(String appUnitPrize) {
        this.appUnitPrize = appUnitPrize;
    }

    public String getAppUnitGift() {
        return appUnitGift;
    }

    public void setAppUnitGift(String appUnitGift) {
        this.appUnitGift = appUnitGift;
    }

    public String getWebUnitPrize() {
        return webUnitPrize;
    }

    public void setWebUnitPrize(String webUnitPrize) {
        this.webUnitPrize = webUnitPrize;
    }

    public String getWebUnitGift() {
        return webUnitGift;
    }

    public void setWebUnitGift(String webUnitGift) {
        this.webUnitGift = webUnitGift;
    }

    public String getMaxGift() {
        return maxGift;
    }

    public void setMaxGift(String maxGift) {
        this.maxGift = maxGift;
    }

    public String getPrize_key() {
        return prize_key;
    }

    public void setPrize_key(String prize_key) {
        this.prize_key = prize_key;
    }

    public String getPresetHits() {
        return presetHits;
    }

    public void setPresetHits(String presetHits) {
        this.presetHits = presetHits;
    }
}
